package yannan.voiplock4ble.bean.ble;

import java.util.Arrays;

import yannan.voiplock4ble.utils.ByteUtils;

/**
 * 说明：
 * 作者：mainTel
 * 时间：2016/12/3 19:34
 * 备注：
 */
public class ConnectLock extends BaseBleResponse {

    //5A A5 1C 00 00 00 10 00 00 00 00 00 01 00 45 A0 01 00 46 57 20 30 30 30 31 00 00 00 00 00 51 3F
    /*
    //手机门锁连接应答
typedef struct {
	AppCommandHead_T head;
	//uint8_t cmd;留在父类
	//uint8_t reserve;	//对齐保留  留在父类
	//uint16_t token;留在父类
	BOOL operResult;			//TRUE,连接成功，FALSE,连接失败
#define PHONE_NOT_MATCH			0		//不匹配
#define PHONE_MATCH_ADMIN 		1		//匹配管理员
#define PHONE_MATCH_NORMAL		2		//匹配普通用户
	uint16_t phoneMatchType;	//手机匹配类型
	uint16_t contentToken;	//内容令牌
	uint16_t protoVersion;		//门锁端协议版本号
	uint8_t firmwareVersion[FIRMWARE_VERSION_LEN];//控制板软件版本号
	 uint8_t fingerFirmwareVersion[FIRMWARE_VERSION_LEN];/指静脉模块软件版本号
}PhoneConnectLockRsp_T;

    5A A5 1C 00 00 00
    10 00 00 00
    =====
    00 00  operResult
    00 00  phoneMatchType
    45 A0  contentToken
    01 00  protoVersion
    46 57 20 30 30 30 31 00 00 00 00 00 firmwareVersion
    ====
    60 CF
     */
    public boolean operResult;
    public int phoneMatchType; //用户权限
    public int contentToken = 0;
    public int protoVersion;
    public String firmwareVersion;
    public String lockserialId;

    public ConnectLock(byte[] response) {
        super(response);
        operResult = (content[0] & 0xFF) == 1;
        int per = content[2] & 0xff;
        if (per == 0) { //游客
            phoneMatchType = 2;
        } else if (per == 1) {//管理员
            phoneMatchType = 0;
        } else if (per == 2) { //普通用户
            phoneMatchType = 1;
        }
        byte[] tokens = Arrays.copyOfRange(content, 4, 6);
        contentToken = Integer.parseInt(ByteUtils.bytesToHexString(new byte[]{tokens[1], tokens[0]}), 16);
        protoVersion = Integer.parseInt(ByteUtils.bytesToHexString(Arrays.copyOfRange(content, 6, 8)), 16);
//        firmwareVersion = ByteUtils.bytesToHexString(Arrays.copyOfRange(content, 8, content.length));
        firmwareVersion = new String(Arrays.copyOfRange(content, 8, content.length));
    }

    public ConnectLock(byte[] response, String lockserialId) {
        super(response);
        this.lockserialId = lockserialId;
    }
}
